#ifndef INPUT_H
#define INPUT_H

#include <QObject>
#include <QThread>
#include <QDateTime>
#include <OISInputManager.h>

#include <Windows.h>

enum ApplicationKey
{
  Ak_None,
  Ak_Up,
  Ak_Down,
  Ak_Left,
  Ak_Right,
  Ak_Enter,
  Ak_Back
};

class ThreadTimer: public QObject
{
  Q_OBJECT

  int _interval;
  QDateTime _lastUpdate;
  bool _running;

public:
  ThreadTimer(QObject* parent=0);

  void setInterval(int msecs);
  int interval() const;
  void update();
  void start();
  void stop();

signals:
  void timeout();
};

// *********************************************************
class InputDevice: public ThreadTimer
{
  Q_OBJECT
public:
  InputDevice(QObject* parent=0);

  virtual void init(OIS::InputManager*)=0;
  virtual void capture()=0;

signals:
  void key(int);

protected:
  ApplicationKey _currentKey;

protected slots:
  void startKeyEmit();
  void stopKeyEmit();
  void keyTimeout();
};

// *********************************************************
class InputThread: public QThread
{
  Q_OBJECT

  QList<InputDevice*> _devices;
  bool _paused;
  OIS::InputManager* _inputManager;

public:
  InputThread(QObject* parent=0);
  void init(QWidget *w);
  void init(HWND hWnd);
  void run();

  void setPaused(bool p) { _paused = p; }

signals:
  void key(int);
};

// *********************************************************
class NativeEventBlocker: public QObject
{
public:
  NativeEventBlocker(QObject* parent=0);
  bool eventFilter(QObject *, QEvent *e);
};

#endif // INPUT_H
